﻿package{
	import flash.events.EventDispatcher;	
	import flash.events.Event;	
	import com.glidecast.models.Segment;
	import com.glidecast.models.Graphic;
	import com.glidecast.models.Audio;
	
	
	
	public class GlideCastModel extends EventDispatcher
	{
		public static var UPDATE:String='ModelUpdated';
		public static var AUDIOUPDATE:String='AudioUpdated';
		public static var GRAPHICUPDATE:String='GraphicUpdated';
		
		private var _gcid: String;
		
		public var needThumb:Boolean = false;
		public var isPaused:Boolean = false;
		
		public function GlideCastModel(g:String)
		{
			this._gcid=g;
			this.audio = new Audio();
			this.graphic = new Graphic();
		}
		
		//you can get the gcid, but only can set it on
		//model init.
		public function get gcid():String
		{
			return this._gcid;
		}
		
		
		/*
			Segments are the individual definitions of each 
			glidecast.
		*/
		
		private var _segments: Array;
		public function get segments():Array
		{
			return this._segments;
		}
		public function set segments(newSegments: Array): void
		{
			this._segments=newSegments;
		}
		
		private var _text: String;
		public function get text():String
		{
			return this._text;
		}
		public function set text(s:String):void
		{
			this._text=s;
			dispatchEvent(new Event(GlideCastModel.UPDATE));
		}
		private var _templatetype: String;
		public function get templatetype():String
		{
			return this._templatetype;
		}
		public function set templatetype(s:String):void
		{
			this._templatetype=s;
			dispatchEvent(new Event(GlideCastModel.UPDATE));
		}
		
		private var _style: String;
		public function get style():String
		{
			return this._style;
		}
		public function set style(s:String):void
		{
			this._style=s;
			dispatchEvent(new Event(GlideCastModel.UPDATE));
		}
		
		private var _audio:Audio;
		public function get audio():Audio
		{
			return _audio;
		}
		public function set audio(s:Audio):void
		{
			_audio=s;
			//_audio.addEventListener(Audio.COMPLETE, audioLoaded);
			try
			{	
				dispatchEvent(new Event(GlideCastModel.AUDIOUPDATE));				
			}
			catch(error:Error)
			{			
				trace("audioLoaded error: " + error);

			}
		}
		public function audioLoaded(event:Event):void
		{
			try
			{	
				dispatchEvent(new Event(GlideCastModel.AUDIOUPDATE));				
			}
			catch(error:Error)
			{			
				trace("audioLoaded error: " + error);

			}
		}
		
		/*
			The controller will initiate the download of the 
			background graphic. Once the download is complete,
			an event will be fired
		*/
		private var _graphic:Graphic;
		public function get graphic():Graphic
		{
			return _graphic;
		}
		public function set graphic(s:Graphic):void
		{
			_graphic=s;
			_graphic.addEventListener(Graphic.COMPLETE, graphicLoaded);
			try
			{	
				dispatchEvent(new Event(GlideCastModel.GRAPHICUPDATE));				
			}
			catch(error:Error)
			{			
				trace("graphicLoaded error: " + error);

			}
		}
		public function graphicLoaded(event:Event):void
		{
			try
			{
				dispatchEvent(new Event(GlideCastModel.GRAPHICUPDATE));				
			}
			catch(error:Error)
			{			
				trace("graphicLoaded error: " + error);

			}
		}
	}
}
